package com.heima.socket.udp.uniacst.talkroom;

import java.io.IOException;
import java.net.*;
import java.util.Scanner;

public class SendDemo {
    public static void main(String[] args) throws IOException {
        /**
         * udp循环发送数据, 直到输入886, 停止发送
         */

        DatagramSocket ds = new DatagramSocket();

        Scanner sc = new Scanner(System.in);
        // 循环发送数据
        while(true) {
            String str = sc.nextLine();
            if(str.equals("886")){
                break;
            }
            byte[] bytes = str.getBytes();
            InetAddress address = InetAddress.getByName("127.0.0.1");
            int port = 10086;

            DatagramPacket dp = new DatagramPacket(bytes, bytes.length, address, port);

            ds.send(dp);

        }
        ds.close();

    }
}
